package com.wind.httpProxyServer.manager;

import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;

public class WhiteListManager {
    public static Map<Long,List<String>> whites=new ConcurrentHashMap<>();

    public static CopyOnWriteArrayList<String> columnWhites=new CopyOnWriteArrayList<>();


    public  static boolean pass(String ip ,String ruleIp){
        String[] splits = ruleIp.split("\\.");
        int num = 0;
        for(int i =splits.length-1 ;i>=0;i--){
            if(splits[i].equals("0")){
                num++;
            }

        }
        int surplusNum = 4 -num;

        if(surplusNum ==0){
            return true;
        }

        StringBuilder result = new StringBuilder();
        for (int i = 0; i < surplusNum; i++) {
            result.append(splits[i]);
            if (i < surplusNum - 1) {
                result.append(".");
            }
        }

        System.out.println(result.toString());

        return ip.startsWith(result.toString());
    }



}
